local oldReadOnly = _G["fs"]["isReadOnly"]
local oldMove = _G["fs"]["move"]
local oldDelete = _G["fs"]["delete"]
local oldHttpGet = _G["http"]["get"]
local oldError = _G["error"]

log.writeBootLog("Initialized system boot log")
log.writeSyslog("Initialized primary system log")
log.writeMessage("Initialized secondary system log")
log.writeSecurity("Initialized security/access log")
log.writeShutdown("Initialized shutdown log")
log.writeAuth("Initialized authorization log")

sleep(0.25)
if http then
 gui.printBootSuccess("HTTP detection succeeded")
else
 gui.printBootWarning("HTTP detection failed")
end
sleep(0.5)
shell.run("/etc/autorun")
gui.printBootWarning("Enumerating user assemblies...")
kernel.loadUserAssemblies(false)
sleep(0.25)
gui.printBootWarning("Initiating security protocols")
_G["fs"]["isReadOnly"] = function(path)
 local find1 = shell.resolve(path)
 if string.find(find1, "boot") or string.find(find1, "etc") or string.find(find1, "bin") or string.find(find1, "sbin") then
  log.writeSecurity("Attempt to access system files!")
  if security.getSU() or _IDENTIFIER then
   log.writeSecurity("Superuser access verified.")
   return false
  else
   log.writeSecurity("Attempt blocked.")
   return true
  end
 elseif find1 == "startup" or find1 == "/startup" then
  log.writeSecurity("Attempt to access bootloader!")
  log.writeSecurity("Attempt blocked.")
  return true
 end 
 return oldReadOnly(path)
end
_G["fs"]["move"] = function(path1, path2)
 local find2 = shell.resolve(path1)
 if string.find(find2, "boot") or string.find(find2, "etc") or string.find(find2, "bin") or string.find(find2, "sbin") then
  log.writeSecurity("Attempt to access system files!")
  if security.getSU() or _IDENTIFIER then
   log.writeSecurity("Superuser access verified.")
  else
   log.writeSecurity("Attempt blocked.")
   exception.throw("RestrictedOpsException")
   return nil
  end
 elseif find2 == "startup" or find2 == "/startup" then
  log.writeSecurity("Attempt to access bootloader!")
  log.writeSecurity("Attempt blocked.")
  exception.throw("RestrictedOpsException")
  return nil
 end 
 return oldMove(path1, path2)
end
_G["fs"]["delete"] = function(path)
 local find3 = shell.resolve(path)
 if string.find(find3, "boot") or string.find(find3, "etc") or string.find(find3, "bin") or string.find(find3, "sbin") then
  log.writeSecurity("Attempt to access system files!")
  if security.getSU() or _IDENTIFIER then
   log.writeSecurity("Superuser access verified.")
  else
   log.writeSecurity("Attempt blocked.")
   exception.throw("RestrictedOpsException")
   return nil
  end
 elseif find3 == "startup" or find3 == "/startup" then
  log.writeSecurity("Attempt to access bootloader!")
  log.writeSecurity("Attempt blocked.")
  exception.throw("RestrictedOpsException")
  return nil
 end 
 return oldDelete(path)
end
_G["http"]["get"] = function(url, headers)
 log.writeSecurity("Downloaded contents of "..url)
 return oldHttpGet(url, headers)
end
_G["error"] = function(text, lvl)
 local x = lvl or 2
 local logger = fs.open("/etc/errorLog", "a")
 logger.writeLine(tostring(os.day()).."d:"..textutils.formatTime(os.time(), true).." | "..text)
 logger.close()
 oldError(text, x or 1)
end
rawset(fs, "_native", {})
rawset(fs, "_native.check", oldReadOnly)
rawset(fs, "_native.move", oldMove)
rawset(fs, "_native.delete", oldDelete)
rawset(http, "_synchronise", oldHttpGet)
rawset(os, "_exception", oldError)
gui.printBootSuccess("Boot sequence stage 2 complete")
sleep(2)
kernel.clear()
shell.run("/etc/auth")